<?php

/*
 * @Date: 2025-08-22 20:47:35
 * @LastEditors: 贾二小 erxiao.jia@outlook.com
 * @LastEditTime: 2025-10-02 15:05:31
 * @FilePath: /admin-api/app/Http/Controllers/UploadController.php
 */

namespace App\Http\Controllers;

use App\Models\Upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class UploadController extends Controller
{
    public function avatar(Request $request)
    {
        //文件信息
        $file = $request->file('file');

        //保存文件
        $upload = new Upload();
        $upload->name = $file->getClientOriginalName();
        $upload->type = $file->getClientMimeType();
        $upload->path = $file->store('avatars');
        $upload->size = $file->getSize();
        $upload->url = Storage::url($upload->path);
        $upload->save();

        return $this->success('上传成功', data: $upload);
    }
}
